# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>

#
# Variables for dotnet build version 3.1
# This APKBUILD is designed to be the same for version 5.0 and under
# except for the variables in this first section
#

pkgname=dotnet31-runtime
pkgver=3.1.24
_bldver=3.1.418-r0
pkgrel=0

# Following for dotnet build version 3.1 and up
_pkgver_macro=${pkgver%.*}
_pkgver_name=${_pkgver_macro//[.0]}
_bldver_ver=${_bldver%%-*}
pkgdesc="The .NET $_pkgver_macro Core runtime"
arch="x86_64"
url=https://www.microsoft.com/net/core
license="MIT"
depends="
	dotnet$_pkgver_name-hostfxr
	icu-libs
	"
makedepends="dotnet$_pkgver_name-build=$_bldver"
subpackages="
	aspnetcore$_pkgver_name-runtime:aspnetcore_runtime:noarch
	aspnetcore$_pkgver_name-targeting-pack:aspnetcore_targeting_pack:noarch
	dotnet$_pkgver_name-apphost-pack:apphost_pack
	dotnet$_pkgver_name-hostfxr:hostfxr
	dotnet$_pkgver_name-targeting-pack:targeting_pack:noarch
	dotnet-host:host
	"
options="!check" # No test suite
source="dotnet.sh"
builddir="$srcdir"

# Function forces dependency on non-virtual host subpackages
# Overrides so that dependency to virtual host subpackage
# can be explicitely set from within subpackage functions
scan_symlink_targets() {
	return
}

build() {
	return
}

package() {
	install -dm 755 \
		"$pkgdir"/usr/share/dotnet/shared \
		"$pkgdir"/usr/share/licenses

	cp -r /usr/share/dotnet/build/$_bldver_ver/shared/Microsoft.NETCore.App "$pkgdir"/usr/share/dotnet/shared/.
	ln -s dotnet-host "$pkgdir"/usr/share/licenses/dotnet$_pkgver_name-runtime
}

host() {
	pkgdesc="A generic driver for the .NET Core Command Line Interface"

	install -dm 755 \
		"$subpkgdir"/etc/profile.d \
		"$subpkgdir"/usr/bin \
		"$subpkgdir"/usr/share/dotnet \
		"$subpkgdir"/usr/share/licenses/dotnet-host

	cp -r /usr/share/dotnet/build/$_bldver_ver/dotnet "$subpkgdir"/usr/share/dotnet/.
	cp -r /usr/share/dotnet/build/$_bldver_ver/LICENSE.txt "$subpkgdir"/usr/share/licenses/dotnet-host/.
	cp -r /usr/share/dotnet/build/$_bldver_ver/ThirdPartyNotices.txt "$subpkgdir"/usr/share/licenses/dotnet-host/.
	ln -s /usr/share/dotnet/dotnet "$subpkgdir"/usr/bin/dotnet
	install -Dm 644 "$srcdir"/dotnet.sh -t "$subpkgdir"/etc/profile.d/
}

hostfxr() {
	pkgdesc="The .NET host resolver contains the logic to resolve and select the right version of the .NET SDK or runtime to use."
	depends="dotnet-host"
	provides="dotnet-hostfxr-$_pkgver_macro=$pkgver"

	install -dm 755 \
		"$subpkgdir"/usr/share/dotnet \
		"$subpkgdir"/usr/share/licenses

	cp -r /usr/share/dotnet/build/$_bldver_ver/host "$subpkgdir"/usr/share/dotnet/.
	ln -s dotnet-host "$subpkgdir"/usr/share/licenses/dotnet$_pkgver_name-hostfxr
}

aspnetcore_runtime() {
	pkgdesc="The ASP.NET $_pkgver_macro Core runtime"
	depends="dotnet$_pkgver_name-runtime"
	provides="aspnetcore-runtime-$_pkgver_macro=$pkgver"

	install -dm 755 \
		"$subpkgdir"/usr/share/dotnet/shared \
		"$subpkgdir"/usr/share/licenses

	cp -r /usr/share/dotnet/build/$_bldver_ver/shared/Microsoft.AspNetCore.App "$subpkgdir"/usr/share/dotnet/shared/.
	ln -s dotnet-host "$subpkgdir"/usr/share/licenses/aspnetcore$_pkgver_name-runtime
}

apphost_pack() {
	pkgdesc="The .NET $_pkgver_macro Core apphost pack"
	provides="dotnet-apphost-pack-$_pkgver_macro=$pkgver"

	install -dm 755 \
		"$subpkgdir"/usr/share/dotnet/packs \
		"$subpkgdir"/usr/share/licenses

	cp -r /usr/share/dotnet/build/$_bldver_ver/packs/Microsoft.NETCore.App.Host.* "$subpkgdir"/usr/share/dotnet/packs/.
	ln -s dotnet-host "$subpkgdir"/usr/share/licenses/dotnet$_pkgver_name-apphost-pack
}

targeting_pack() {
	pkgdesc="The .NET $_pkgver_macro Core targeting pack"
	provides="dotnet-targeting-pack-$_pkgver_macro=$pkgver"

	install -dm 755 \
		"$subpkgdir"/usr/share/dotnet/packs \
		"$subpkgdir"/usr/share/licenses

	cp -r /usr/share/dotnet/build/$_bldver_ver/packs/Microsoft.NETCore.App.Ref "$subpkgdir"/usr/share/dotnet/packs/.
	ln -s dotnet-host "$subpkgdir"/usr/share/licenses/dotnet$_pkgver_name-targeting-pack
}

aspnetcore_targeting_pack() {
	pkgdesc="The ASP.NET $_pkgver_macro Core targeting pack"
	provides="aspnetcore-targeting-pack-$_pkgver_macro=$pkgver"

	install -dm 755 \
		"$subpkgdir"/usr/share/dotnet/packs \
		"$subpkgdir"/usr/share/licenses

	cp -r /usr/share/dotnet/build/$_bldver_ver/packs/Microsoft.AspNetCore.App.Ref "$subpkgdir"/usr/share/dotnet/packs/.
	ln -s dotnet-host "$subpkgdir"/usr/share/licenses/aspnetcore$_pkgver_name-targeting-pack
}
sha512sums="
e61b9e3e5a2305646a616d598378230c9755c5dd5363692cc363f8f4add3807563c324dd86f3a7ae9d358c82d730608e7b293935a2b6c81c0c0f62d752a0a1cf  dotnet.sh
"
